word='ada'
class WordDictionary:

    def __init__(self):
        self.isEnd=False
        self.next=dict()
    def addWord(self, word: str) -> None:
        node=self
        for ch in word:
            if ch not in node.next.keys():
                node.next[ch]=WordDictionary()
            node=node.next[ch]
        node.isEnd=True
    def search(self, word: str) -> bool:
        return self.dfs(len(word),0,word,self)
    def dfs(self,wordLen,index,word,node):
        if index==wordLen:
            return node.isEnd
        if word[index]==".":
            print("遇到.了,走if",word[index])
            for key in node.next.keys():
                if self.dfs(wordLen,index+1,word,node.next[key]):
                    return True
            return False
        else:
            print("走else",word[index])
            if word[index] in node.next:
                return self.dfs(wordLen,index+1,word,node.next[word[index]])
            else:
                return False

# Your WordDictionary object will be instantiated and called as such:
obj = WordDictionary()
obj.addWord('bad')
obj.addWord("dad")
obj.addWord("mad")
param_2 = obj.search('pad')

print(param_2)
